DEFINE VARIABLE par AS CHARACTER.
DEFINE VARIABLE comp AS CHARACTER.
DEFINE VARIABLE ref LIKE ps_ref.
DEFINE VARIABLE prc1 AS DECIMAL FORMAT ">>>>>9.99<<<".
DEFINE VARIABLE prc2 AS DECIMAL FORMAT ">>>>>9.99<<<".


FOR EACH ps_mstr WHERE ps_par = "P15-3505102" AND ps_comp BEGINS "" NO-LOCK:
    RUN LowestPrice(INPUT ps_par,INPUT ps_comp ,INPUT ps_ref,OUTPUT prc1, OUTPUT prc2).
    IF prc1<> prc2 THEN DISP ps_par ps_comp ps_qty_per prc1 prc2 WITH DOWN FRAME c.
END.

PROCEDURE LowestPrice :
    DEFINE INPUT PARAMETER par LIKE ps_par.
    DEFINE INPUT PARAMETER comp LIKE ps_comp.
    DEFINE INPUT PARAMETER ref LIKE ps_ref.
    DEFINE OUTPUT PARAMETER LowestPrice LIKE sct_cst_tot INITIAL 99999 .
    DEFINE OUTPUT PARAMETER SubLowestPrice LIKE sct_cst_tot INITIAL 99999 .

    FOR FIRST ptp_det NO-LOCK WHERE ptp_part = comp AND ptp__chr01 = "C",
        FIRST sct_det NO-LOCK WHERE sct_sim = "CURRENT" AND sct_part = ptp_part AND sct_site = ptp_site:
        ASSIGN 
                SubLowestPrice = sct_cst_tot.
                LowestPrice = sct_cst_tot.
        DISP comp sct_cst_tot Lowestprice Sublowestprice WITH FRAME a.
    END.

    FOR EACH pts_det NO-LOCK WHERE pts_par = par AND pts_part = comp AND (ref = "" or LOOKUP(ref,pts_rmks, ",") > 0) :
       
        DISP pts_part pts_sub_part WITH DOWN FRAME b.
        FIND FIRST ptp_det NO-LOCK WHERE ptp_part = pts_sub_part AND ptp__chr01 = "C" NO-ERROR.
        IF NOT AVAILABLE ptp_det THEN LEAVE .
        FIND FIRST sct_det NO-LOCK WHERE sct_sim = "CURRENT" AND sct_part = pts_sub_part AND sct_site = ptp_site.
        IF sct_cst_tot <= LowestPrice THEN
            ASSIGN 
                SubLowestPrice = LowestPrice
                LowestPrice = sct_cst_tot.
        ELSE IF sct_cst_tot < SubLowestPrice THEN
            ASSIGN
                SubLowestPrice = sct_cst_tot.
        ELSE IF abs(SublowestPrice - LowestPrice) <= 0.00000001 THEN 
            ASSIGN 
                SubLowestPrice = sct_cst_tot.
        DISP sct_cst_tot Lowestprice Sublowestprice WITH FRAME b.
    END.
END.
 
